/**********************************************************************************************************************
 *
 * Project:    mGameEngine
 * File:       application.h
 * Author:     karooolek
 * Created on: 2009-01-06
 *
 **********************************************************************************************************************/

#ifndef APPLICATION_H_
#define APPLICATION_H_

#include "window.h"
#include "../common.h"
#include "../input.h"
#include <AL/alut.h>
#include <NxPhysics.h>
#include <NxCooking.h>
#ifdef WIN32
#include <winsock2.h>
#endif

namespace mGameEngine
{
namespace System
{

/**
 * Application.
 */
class Application : public Thread
{
private:
    // GLUT callbacks
    static Application *_app;
    static void _glutDisplayFunc();
    static void _glutIdleFunc();

    /**
     * Run application.
     * Application creates window.
     * Creates context for OpenGL, OpenAL and PhysX.
     * Creates and runs two loops: idle loop (main loop) and draw loop (rendering).
     */
    void _run(void);

protected:
    /**
     * Applications name
     */
    String _name;

    /**
     * Applications version
     */
    String _version;

public:
    /**
     * Create new application with default name and version.
     */
    Application();

    /**
     * Create new application with initial name and version.
     * @param name applications name
     * @param version applications version
     */
    Application(const String &name, const String &version);

    /**
     * Destroy application.
     */
    virtual ~Application();

    /**
     * Get applications name
     * @return applications name
     */
    const String &getName() const
    {
        return _name;
    }

    /**
     * Set applications name
     * @param name applications name
     */
    void setName(const String &name)
    {
        _name = name;
    }

    /**
     * Get applications version
     * @return applications version
     */
    const String &getVersion() const
    {
        return _version;
    }

    /**
     * Set applications version
     * @param version applications version
     */
    void setVersion(const String &version)
    {
        _version = version;
    }

    /**
     * Begin application.
     */
    virtual void begin();

    /**
     * End application.
     */
    virtual void end();

    /**
     * Application main loop.
     */
    virtual void idle();

    /**
     * Application draw loop.
     */
    virtual void draw() const;

};

}
}

#endif // APPLICATION_H_
